﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using QuartzServices.Application.SystemLog;
using QuartzServices.Application.SystemLog.Models;
using QuartzServices.Infrastructure.Common.Extensions;

namespace QuartzServices.Web.Controllers
{
    public class SystemLogController : Controller
    {

        private readonly ISystemLogApplication _systemLogApplication;
        private readonly IConfiguration _configuration;
        private readonly ILogger<SystemLogController> _logger;

        public SystemLogController(ILogger<SystemLogController> logger,ISystemLogApplication systemLogApplication,IConfiguration configuration)
        {
            _logger = logger;   
            _systemLogApplication = systemLogApplication;
            _configuration = configuration;
        }

        public IActionResult Index()
        {
             return View();
        }

        [HttpGet]
        public async Task<IActionResult> PageList(SystemLogPageRequestModel model)
        {
            var pageResult = await _systemLogApplication.PageList(model);
            return Content(JsonConvert.SerializeObject(pageResult));
        }

        [HttpGet]
        public IActionResult GetSwaggerUrl() 
        {
            var url = _configuration["SwaggerUrl"];
            return Content(JsonConvert.SerializeObject(new { url }));
        }

        [HttpPost]
        public async Task<IActionResult> Delete(List<string> ids) 
        {
            await _systemLogApplication.Delete(ids);
            return Content("");
        }
    }
}
